#include <d3d9.h>
#include <d3dx9.h>
#include <string>

#include "../Solaire/Renderer.h"
#include <vector>
#include "DirectXSprite.h"
#include "../Solaire/Animation.h"

#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")


class DirectX : public Renderer, Service<DirectX>
{
	struct EffectHandle
	{
		D3DXHANDLE MatrixHandle;
		D3DXHANDLE TextureHandle;
		D3DXHANDLE Technique;
	};

	struct shader
	{
		ID3DXEffect* Effect;
		EffectHandle Handles;
		std::string Name;
	};

	struct sprite
	{
		DirectXSprite m_sprite;
		std::wstring m_fileName;
	};

public:
	DirectX();
	~DirectX();
	bool Init(HWND hWnd, UINT uiWidth, UINT uiHeight);
	bool LoadShaders();
	void render_frame( double frameTime );    // renders a single frame
	ISprite* LoadSprite( std::wstring fileName, int frameWidth, int frameHeight );
	

	//DEBUG
	//void MoveSprite( int x, int y );
private:
	D3DXMATRIX BuildProjectionMatrix();

private:
	LPDIRECT3D9 m_d3d;    // the pointer to our Direct3D interface
	LPDIRECT3DDEVICE9 m_d3ddev;    // the pointer to the device class
	D3DPRESENT_PARAMETERS m_d3dpp; // the parameter list of the d3d device
	IDirect3DVertexDeclaration9* m_declaration;
	shader m_SimpleSurfaceShader;

	LPDIRECT3DTEXTURE9 pPyramideTexture;
	LPDIRECT3DVERTEXBUFFER9 v_buffer;

	UINT m_uiWidth;
	UINT m_uiHeight;
	float m_fWidth;
	float m_fHeight;

	std::vector<sprite> m_sprites;
	Animation animation;


	////DEBUG
	int m_x,m_y;
};
